package com.qf.service.impl;

import com.qf.entity.Goods;
import com.qf.mapper.GoodsMapper;
import com.qf.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

//商品业务逻辑层
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    public GoodsMapper goodsMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 通过商家的id去查询商家对应的商品
     * @param m_id
     * @return
     */
    @Override
    public List<Goods> selGoodsByMerchantId(int m_id) {
       /* Boolean bool = redisTemplate.hasKey("gyt");
        List list = null;
        if (!bool) {  //没有
            List<Goods> goods =  goodsMapper.selGoodsByMerchantId(m_id);//数据库查询
            System.out.println("AAAAAAAAAAAAAAAAAAA---数据库查询---AAAAAAAAAAAAAAAAAAAAAA");
            redisTemplate.opsForList().rightPushAll("gyt", goods); //往redis放一份
            list = redisTemplate.opsForList().range("gyt", 0, -1);//直接redis取值
            System.out.println("22222222222288888888888888888888888888-----------------------------------");
            return list;
        } else { //有
            System.out.println("AAAAAAAAAAAAAAAAAAA---redis查询---AAAAAAAAAAAAAAAAAAAAAA");
            list = redisTemplate.opsForList().range("gyt", 0, -1);//直接redis取值
        }
        return list;*/
       return goodsMapper.selGoodsByMerchantId(m_id);
    }
    /**
     * 通过商品的id去查询商品
     * @param g_id
     * @return
     */
    @Override
    public Goods selByGoodsId(int g_id) {
        return goodsMapper.selByGoodsId(g_id);
    }
}
